package com.hspedu.newData.dmsxl.字符串.回文串;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-09 
 * @Version: 1.0
 */

public class LC125验证回文串 {

    public boolean isPalindrome(String s) {

        int i = 0;
        int j = s.length() - 1;

        char[] charArray = s.toCharArray();

        while (i < j){

            while (!isTrue(charArray[i])){
                i++;
            }
            while (!isTrue(charArray[j])){
                j--;
            }

            if (converted((charArray[i])) != converted(charArray[j])){
                return false;
            }
            i++;
            j--;
        }
        return true;
    }

    public boolean isTrue(char c){
        return (c>='A' && c <= 'Z') || (c>='a' && c<='z')||(c>='0' && c<='9');
    }

    public char converted(char c){
        if (c>='A' && c <= 'Z'){
            c += 32;
        }
        return c;
    }


    @Test
    public void test() {
        // 测试代码

        boolean palindrome = isPalindrome("A man, a plan, a canal: Panama");
        boolean palindrome1 = isPalindrome("A man, a plan, a canal: P");

        System.out.println("111");
    }
}
